import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

class CampusController extends GetxController {
  WebViewController? wc1;
  WebViewController? wc2;
  WebViewController? wc3;

  List _list = [
    {'img': 'assets/img/campus/school.jpg', 'title': '聊大官网', 'id': 1},
    {'img': 'assets/img/campus/weibo.png', 'title': '聊大超话', 'id': 2},
    {'img': 'assets/img/campus/tieba.jpg', 'title': '聊大贴吧', 'id': 3},
  ];

  List get list => _list;

  tapTo(e) {
    switch (e["id"]) {
      case 1:
        Get.to(() => Scaffold(
            appBar: AppBar(
              title: Text("聊大官网"),
            ),
            body: WebViewWidget(controller: wc1!)));
        break;
      case 2:
        Get.to(() => Scaffold(
            appBar: AppBar(
              title: Text("聊大超话"),
            ),
            body: WebViewWidget(controller: wc2!)));
        break;
      case 3:
        Get.to(() => Scaffold(
            appBar: AppBar(
              title: Text("聊大贴吧"),
            ),
            body: WebViewWidget(controller: wc3!)));
        break;
    }
  }

  @override
  void onInit() {
    wc1 = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse('https://www.lcu.edu.cn/'));

    wc2 = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse(
          'https://m.weibo.cn/p/100808d1644559e687c3fd710090267e96b2cd/topic_album'));

    wc3 = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse(
          'https://tieba.baidu.com/f?kw=%E8%81%8A%E5%A4%A7%E8%B4%B4%E5%90%A7'));
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {}
}
